package com.cw.lang.common.converter;

import com.cw.lang.common.dto.BaseDto;
import com.cw.lang.common.model.BaseDo;

/**
 * 基础转换类
 *
 * @author chenw
 * @date 2021/11/10
 */
public class BaseConverter {
    /**
     * dto转do
     *
     * @param baseDto
     * @return
     */
    public static BaseDo dto2Do(BaseDto baseDto) {
        if(baseDto == null){
            return null;
        }
        return BaseDo.builder()
            .id(baseDto.getId())
            .deleted(baseDto.getDeleted())
            .version(baseDto.getVersion())
            .createBy(baseDto.getCreateBy())
            .createDate(baseDto.getCreateDate())
            .createDateStart(baseDto.getCreateDateStart())
            .createDateEnd(baseDto.getCreateDateEnd())
            .updateBy(baseDto.getUpdateBy())
            .updateDate(baseDto.getUpdateDate())
            .updateDateStart(baseDto.getUpdateDateStart())
            .updateDateEnd(baseDto.getUpdateDateEnd())
            .build();
    }

    /**
     * do转dto
     *
     * @param baseDo
     * @return
     */
    public static BaseDto do2Dto(BaseDo baseDo) {
        if(baseDo == null){
            return null;
        }
        return BaseDto.builder()
            .id(baseDo.getId())
            .deleted(baseDo.getDeleted())
            .version(baseDo.getVersion())
            .createBy(baseDo.getCreateBy())
            .createDate(baseDo.getCreateDate())
            .createDateStart(baseDo.getCreateDateStart())
            .createDateEnd(baseDo.getCreateDateEnd())
            .updateBy(baseDo.getUpdateBy())
            .updateDate(baseDo.getUpdateDate())
            .updateDateStart(baseDo.getUpdateDateStart())
            .updateDateEnd(baseDo.getUpdateDateEnd())
            .build();
    }
}
